<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .active{
            color: red;
        }
    </style>
</head>
<body>
    
    <div id="app">
        <router-link to="/list/1">第一页</router-link>
        <router-link to="/list/2">第二页</router-link>
        <router-link to="/list/3">第三页</router-link>
        <router-link to="/home">回到主页</router-link>

        <router-view></router-view>
    </div>

    <template id="list">
        <div>
            <h3>我就是第{{this.$route.params.pageNum}}页</h3>
        </div>
    </template>

    <template id="home">
        <div>
            <h2>我是home</h2>
        </div>
    </template>

    <script src="../lib/Vue/vue.js"></script>
    <script src="../lib/Vue/vue-router.js"></script>
    <script>

        const router = new VueRouter({
            routes: [
                {
                    path: '/list/:pageNum',
                    component: {
                        template: '#list',
                        beforeRouteUpdate(to, from, next) {
                            console.log('beforeRouteUpdate');
                            var confirm = window.confirm('要离开么')
                            if (confirm) {
                                next()
                            } else {
                                next(false)
                            }
                        }
                    }
                },
                {
                    path: '/home',
                    component: {
                        template: '#home',
                        beforeRouteEnter (to, from, next) {
                            console.log(this);
                            next()
                        }
                    }
                }
            ],
            linkActiveClass: 'active'
        })

        var vm = new Vue({
            el: '#app',
            router
        })
    </script>
</body>
</html>